<template>
  <el-config-provider :locale="zhCn">
    <NuxtLayout>
      <NuxtPage />
    </NuxtLayout>
  </el-config-provider>
</template>
<script setup>
import { ElConfigProvider } from "element-plus";
import zhCn from "element-plus/es/locale/lang/zh-cn";
useSeoMeta({
  title: "神奇网站",
  description: "这是我的神奇网站，让我来告诉你关于它的一切。",
  keywords: ["神奇网站, 神奇功能, 神奇技巧"],
});

// const navCurrent
useHead({
  // 作为字符串，
  titleTemplate: (productCategory) => {
    return productCategory ? `${productCategory}-神奇网站` : "神奇网站";
  },
});

// element-plus 图标
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
// You might choose this based on an API call or logged-in status
const layout = "main-content";

const nuxtApp = useNuxtApp();
// console.log(nuxtApp)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  nuxtApp.vueApp.component(key, component);
}

// 加载产品分类菜单
const { data: result } = await useFetch("/api/categoryList");
const categoryList = result.value.data;
const navList = useNav();
navList.value.forEach((item) => {
  if (item.url === "/product") {
    // 获取接口分类列表
    categoryList.forEach((cateItem) => {
      cateItem.label = cateItem.category_name;
      cateItem.url = `/product/${cateItem.category_id}`;
      if (cateItem.children) {
        cateItem.children.forEach((child) => {
          child.label = child.category_name;
          child.url = `/product/${child.category_id}`;
        });
      }
      return cateItem;
    });
    item.children = categoryList;
  }
});
</script>
<style lang="less">
@primary-color: #009ca3;
</style>
